<style type="text/css">

   table,tr,th,td {
        border: 1px solid #f4f4f4;
   }
   .table {
    /*padding: 0 6.5%;*/
 /*   display: flex;
    flex-flow: row;
    align-items: center;*/
   }
   .table>table {
    width: 100%;
   }
   .table th,.table tr,.table td {
    text-align: center;
   }
   .table th,.table td {
    padding: 10px 0;
   }
   .table td {
    background-color: #f5f5f5;
   }
   .inp>td>input {
    width: 60%;
    border: none;
    outline: none;
    background: transparent;
    text-align: center;
   }
   .inp>td {
    text-align: center;
   }
   .button>button{
    width: 80px;
    background-color: red;
    color: #fff;
    text-align: center;
    padding: 10px;
    border-radius: 5px;
   }
   .time {
    width: 15%;
   }
   .set {
    background:#fff;
    color:#5fb878;
   }
   .set>input {
    width: 100% !important;
    max-width: 100px;
    border: 1px solid #e8e6e6 !important;
   }
   .mr {
    width: 7%;
   }
   .button>button {
    outline: none;
    border: none;
   }
   .inp>td:nth-child(1) {
    width: 5%;
   }

   .form-group {
    margin: 20px auto !important;

   }
   .max {
    width: 12%;
   }


</style>
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">开始时间:</label>
        <div class="col-xs-12 col-sm-8">

            <div class="layui-inline">
        
              <div class="layui-input-inline">
                <input type="text" class="layui-input" id="start" value="{$seckill.start_time|date = 'Y-m-d H:i:s',###}" placeholder="yyyy-MM-dd HH:mm:ss">
     
</div>
  </div>
            
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">结束时间:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="layui-inline">
        
                <div class="layui-input-inline">
                    <input type="text" class="laydate-icon layui-input" value="{$seckill.end_time|date = 'Y-m-d H:i:s',###}" id="end" placeholder="yyyy-MM-dd HH:mm:ss">
                </div>
            </div>

        </div>
    </div>
    
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">选择商品:</label>
        <button type="button" id="jumpNewPage" class="btn btn-xs btn-primary btn-dialog">选择</button>
    </div>
    <div class="form-group table" style="">
        <table border="0" class="Table">
            <tr>
                <th class="max">商品名称</th>
                <th class="max">原价</th>
                <th class="max">原库存</th>
                <th>秒杀价格</th>
                <th>秒杀库存</th>
                <th>限购</th>
                <th>添加时间</th>
                <th>更新时间</th>
                <th>操作</th>
            </tr>
            {volist name="seckill_choice" id="vo"}
                <tr class='inp'>
                    <td >
                      {$vo.title|mb_substr=0,15,'utf-8'}...
                    </td>
                    <td class="mr">
                      <input type="text" name="original_price" value="{$vo.original_price}" disabled>
                    </td>
                    <td  class="mr ">
                      <input type="text" name="" value="1000" disabled>
                    </td>
                    <td class="set maxMoney" >
                      <input type="text" class="seckill_price" name="" value="{$vo.seckill_price}" >
                    </td>
                   
                    <td class="set maxNum"> 
                      <input type="text" class="seckill_inventory" name="" value="{$vo.seckill_inventory}" >
                    </td>
                    <td class="set xiangou">
                      <input type="text" class="quota" name="" value="{$vo.quota}" >
                    </td>
                    <td class="time">{$vo.endtime|date = 'Y-m-d H:i:s',###}</td>
                    <td class="time">{$vo.updatetime|date = 'Y-m-d H:i:s',###}</td>
                    <td class="button">
                      <button   onclick="del({$vo.id},{$vo.seckill_choice_id})">删除</button>
                    </td>
                    <input type="hidden" class="vo-id" name="" value="{$vo.id}">
                    <input type="hidden" class="seckill-choice-id" name="" value="{$vo.seckill_choice_id}">
                </tr>
            {/volist} 
        </table>
        <input type="hidden" id="url" value="{:url('activity/details/details',['seckill_id'=>$seckill.id])}"/>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit"  class="submit btn btn-success btn-embossed">确认</button>
            
        </div>
    </div>        
</form>
<script type="text/javascript"  src="/public/assets/layui/layui.js"></script>
<script type="text/javascript"  src="/public/assets/js/jquery.min.js"></script>
<link href="/public/assets/layui/css/layui.css"/>
<script type="text/javascript">
    $(function () { 
        layui.use(['laydate','layer'], function(){
        var laydate = layui.laydate;
          var layer = layui.layer;
            //日期时间选择器
              laydate.render({
                elem: '#start'
                ,type: 'datetime'
                ,theme: '#393D49'
                ,done: function(value, date, endDate){
                    console.log(value) //得到日期生成的值，如：2017-08-18
                },
                ready:function(){
                    $('.laydate-prev-y').text('<<');
                    $('.laydate-prev-m').text('<');
                    $('.laydate-next-m').text('>');
                     $('.laydate-next-y').text('>>');
                }
              });
              laydate.render({
                elem: '#end'
                ,type: 'datetime'
                ,done: function(value, date, endDate){
                    console.log(value) //得到日期生成的值，如：2017-08-18
                },
                ready:function(){
                    $('.laydate-prev-y').text('<<');
                    $('.laydate-prev-m').text('<');
                    $('.laydate-next-m').text('>');
                     $('.laydate-next-y').text('>>');
                }
              });

        document.getElementById('jumpNewPage').onclick = function (e) {
            var url = document.getElementById('url').value;
            console.log(url);

            var op = layer.open({
                title:'秒杀产品',
                type:2,
                content: url,
                maxmin: true,
                area: ['80%', '80%'],
                success:function(){

                    var timer = setInterval(function(){
                        var status = sessionStorage.getItem('status');
                        
                        if (status == '1') {
                            sessionStorage.clear();
                              layer.close(op);
                              window.location.reload();
                            clearInterval('timer');
                        }
                    },200)
                }
            })
        
        }


          $('.maxNum').each(function(){
            $(this).children().on('blur',function(){
         
              if ($(this).val() > $(this).parent().prev().prev().children().val()*1) {
                layer.msg('秒杀库存不能大于原库存')
                $(this).val('');
              }
            })
        })   

          $('.xiangou').each(function(){
            $(this).children().on('blur',function(){
              console.log($(this).val())
              console.log($(this).parent().prev().prev().text()*1)
              if ($(this).val() > $(this).parent().prev().prev().prev().children().val()*1) {
                layer.msg('秒杀限购不能大于原库存')
                $(this).val('');
              }
            })
        })  
     $('.maxMoney').each(function(){
            $(this).children().on('blur',function(){
              if ($(this).val() > $(this).parent().prev().prev().children().val()*1) {
                layer.msg('秒杀价格不能大于原价格')
                $(this).val('');
              }
            })
        })   
        
    });
})

  function del(id,seckill_choice_id){
      var id = id;
      console.log(id);
      var seckill_choice_id = seckill_choice_id;
      console.log(seckill_choice_id);
      var url_ = "{:url('activity/details/del1')}";
      $.ajax({
        type:'post',
        url:url_,
        data:{
          id:id,
          seckill_choice_id:seckill_choice_id
        },
        dataType:"json",
        success:function(msg){
          if(msg.state == 1){
            console.log('删除成功');
          }else{
              layer.msg('删除失败！');
          }
        }
      })
  }
  $('.submit').click(function(){
      var data = [];
      $('.inp').each(function(x,y){
        var arr = {
          seckill_price:$(this).children().eq(3).children().val(),
          seckill_inventory:$(this).children().eq(4).children().val(),
          quota:$(this).children().eq(5).children().val(),
          pid:$('.vo-id').eq(x).val(),
          choice_id:$('.seckill-choice-id').eq(x).val()
        };
    
        data.push(arr)
      })
      
      data = JSON.stringify(data);
      console.log(data);
      var url_ = "{:url('activity/examine/index')}";
      $.ajax({
        type:'post',
        url:url_,
        data:{data:data},
        dataType:"json",
        success:function(msg){
          var stringify = JSON.stringify(data);
          console.log(stringify);
        }         








        

      })
    


  })
    
             
        
    
</script>
